#include <cstdlib>
#include <iostream>

// Note: some implementations require double instead of long double
long double probabillity(unsigned numbers, unsigned picks);
int main(void)
{
    //srand((unsigned)time(0));
    //int n1 = random() % 47 + 1;   // 5 times
    //int n2 = rand() % 27 + 1;   // 1 time
    using namespace std;
    double result, choices;
    cout << "Enter the total number of choices on the game card and \n"
         "the number of picks allowed:\n";
    //while((cin >> total >> choices) && choices <= total)
    while ((cin >> choices) && choices != -1)
    {
        cout << "You have one chance in ";
        //cout << probabillity(total, choices);    // compute the odds
        //result = probabillity(47, 5) * probabillity(27, 1);
        for (int i = 0; i < choices; i++)
        {
            result = probabillity(47, 5) * probabillity(27, 1);
        }
        cout << result;
        cout << " of winning.\n";                                                       
        cout << "Next two numbers (q to quit): ";
        choices--;
    }
    //double result;
    //result = probabillity(47, 5) * probabillity(27, 1);
    cout << "bye\n";
}
// the following function calculates the probabillity of picking picks
// numbers correctly from numbers choices
long double probabillity(unsigned numbers, unsigned picks)
{
    long double result = 1.0;   // here come some local variables
    long double n;
    unsigned p;

    for(n = numbers, p = picks; p > 0; n--, p--)
    {
        result = result * n / p;
    }

    return result;
}